<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        var cookies = {
            set: function (key, expTime) {
                var exp = new Date();
                exp.setTime(exp.getTime() + expTime);
                //var random = parseInt(Math.random() * 1000000);
                var random = this.generateMixed(6);
                var value = exp.getTime() + '_' + random;
                document.cookie = key + '=' + value + ';expires=' + exp.toGMTString() + ';path=/';
            },
            /**
             * @desc Get the value of given cookie key
             * @param key {String} Id to use for lookup
             * @return {String} Return the key of value
             */
            get: function (key) {
                //
                var arr, reg = new RegExp("(^| )" + key + "=([^;]*)(;|$)");
                if (arr = document.cookie.match(reg)) return unescape(arr[2]);
                else return '';
            },
            isCookieExisted: function (key) {
                var val = this.get(key);
                var ret = false;
                if (!!val) {
                    ret = true;
                }
                return ret;
            },
            generateMixed: function (length) {
                var chars = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'];
                var res = "";
                for (var i = 0; i < length; i++) {
                    var id = Math.ceil(Math.random() * 35);
                    res += chars[id];
                }
                return res;
            }
        };
    </script>
</head>
<body>
<script>
    //cookie
//    cookies.set('get_cookie_deviceid',100000);
//    alert(document.cookie)
//    alert(cookies.get('get_cookie_deviceid'))
    //localstorage
//    alert(1)
    localStorage.setItem('get_localstorage_deviceid','爱吃炒菜');
    alert(localStorage.getItem('get_localstorage_deviceid'))
</script>
</body>
</html>